<template>
	<page-body>
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center prepare_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
				<view class='flex flex-wrap align-center justify-between flex-sub prepare_fd0_0'>
					<view class='flex flex-wrap align-center prepare_fd0_0_c0'>
						<text class='fu-iconfont2  prepare_fd0_0_c0_c0' @tap.stop="handleJumpDiy" data-type="back"
							data-url="1">&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='prepare_fd0_0_c1_c0'>{{$t('课前预习')}}</text>
					</view>
					<view class='flex flex-wrap align-center justify-end prepare_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class=" tab-outer">
				<view>
					<benben-flex-tabs class-name='prepare_benbenTabsfd1_0' v-model="tabsVal" ref="benben_tabsfd1_0"
						select-mark="benben_tabsfd1_0" key="benben_tabsfd1_0" :open-title-type='false'
						:open-sticky='true' :top='0' :is-show-content='false' :scrollspy='false'
						:tabs-info.sync="tabsInfofd1_0">

						<scroll-view @scroll="tabsInfofd1_0.scrollX = $event.detail.scrollLeft" id="benben_tabsfd1_0"
							class="benben-tabs" style="width:750rpx" :scroll-x="true" :scroll-left="tabsInfofd1_0.moveX"
							scroll-with-animation="all .3s ease">
							<view class="benben-tabs-content" id="benben_tabsfd1_0-content">
								<view id="benben_tabsfd1_0-title"
									class="benben-tabs-title flex flex align-center justify-around">
									<template v-for='(item,key0) in tabs'>
										<view :key='key0'
											:class="{ 'checkTitlefd1_0': tabsVal == item.value, 'flex flex-wrap align-center': true }"
											class="checkTitlefd1_0_all" @tap="tabsVal = item.value"
											:id="`benben_tabsfd1_0-title-item-${item.value}`">

											<text>{{item.name}}</text>

										</view>
									</template>
								</view>
								<view :style="{ left: tabsInfofd1_0.lineleft, maxWidth: tabsInfofd1_0.lineWidth ,}"
									id="benben_tabsfd1_0-line"
									class="benben-tabs-line flex benben-flex-tabs-line prepare_linefd1_0"
									:class="{'benben-tabs-line-active':tabsInfofd1_0.isInit}"></view>
							</view>
						</scroll-view>

					</benben-flex-tabs>

				</view>
			</view>

			<!---flex布局flex布局结束-->
			<!---flex布局flex布局开始-->
			<view class=" prepare_flex_2" v-if=" tabsVal=='1'">
				<view class='flex flex-direction flex-wrap align-stretch prepare_fd2_0' v-for="item in list"
					:key="item.aid">
					<view class='flex flex-wrap align-center prepare_fd2_0_c0'>
						<!-- <text class='prepare_fd2_0_c0_c0'>{{$t('知识点一：')}}</text> -->
						<text class='prepare_fd2_0_c0_c1'>{{item.examkeypoints_title}}</text>
						<image class='prepare_fd2_0_c0_c2' mode="aspectFit" :src='STATIC_URL+"1608.png"'
							@tap="aianalyse(item.aid,item.examkeypoints_title)"></image>
					</view>
					<view class='flex flex-wrap align-center justify-between prepare_fd2_0_c1'>
						<view class='flex flex-wrap align-center'>
							<text class='prepare_fd2_0_c1_c0_c0'>{{$t('难易程度')}}</text>
							<view class='flex flex-wrap align-center'>
								<template v-for="starNum in [1,2,3,4,5]">
									<image v-if="item.level >= starNum" :key="starNum"
										class='prepare_star1fd2_0_c1_c0_c1' mode="aspectFit"
										:src='STATIC_URL+"428.png"'></image>
									<image v-else :key="starNum" class='prepare_star1fd2_0_c1_c0_c1' mode="aspectFit"
										:src='STATIC_URL+"294.png"'></image>
								</template>
							</view>
						</view>
						<view class='flex flex-wrap align-center'>
							<text class='prepare_fd2_0_c1_c0_c0'>{{$t('掌握程度')}}</text>
							<view class='flex flex-wrap align-center'>
								<template v-for="starNum in [1,2,3,4,5]">
									<image v-if="item.mastery_level >= starNum" :key="starNum"
										class='prepare_star1fd2_0_c1_c1_c1' mode="aspectFit"
										:src='STATIC_URL+"428.png"'></image>
									<image v-else :key="starNum" class='prepare_star1fd2_0_c1_c0_c1' mode="aspectFit"
										:src='STATIC_URL+"294.png"'></image>
								</template>
							</view>
						</view>
					</view>
					<view class='flex flex-wrap align-center prepare_fd2_0_c2' v-if="item.show">
						<view class='flex flex-wrap align-center flex-sub prepare_fd2_0_c1'>
							<text class='prepare_fd2_0_c2_c0_c0'>{{$t('AI分析：')}}</text>
						</view>
						<u-loading-icon style="margin: 0 280rpx 0 0; width: 80rpx;"
							:show="item.show&&!analyse"></u-loading-icon>
						<view class='prepare_fd2_0_c2_c1' v-if="analyse" v-html="analyse"></view>
					</view>
				</view>
			</view>

			<!---flex布局flex布局结束-->
			<!---flex布局flex布局开始-->
			<view class="prepare_flex_2">
				<view class='flex flex-direction flex-wrap align-stretch flex-sub prepare_fd3_0' v-if=" tabsVal=='2'">
					<view v-for='(item,key0) in datum'>
						<!-- map4 -->
						<view class='flex flex-wrap align-center justify-between prepare_fd3_0_c0'
							v-if=" item.file_type==2" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='prepare_fd3_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"1610.png"'>
								</image>
								<text class='prepare_fd3_0_c0_c0_c1'>{{item.name}}</text>
							</view>
							<button class='prepare_fd3_0_c0_c1'
								@tap="seePdf(item.file_path[0],item.aid)">{{$t('查看')}}</button>
						</view>
						<!-- pdf -->
						<view class='flex flex-wrap align-center justify-between prepare_fd3_0_c0'
							v-if=" item.file_type==5" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='prepare_fd3_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"1611.png"'>
								</image>
								<text class='prepare_fd3_0_c0_c0_c1'>{{item.name}}</text>
							</view>
							<button class='prepare_fd3_0_c0_c1'
								@tap="seePdf(item.file_path[0],item.aid)">{{$t('查看')}}</button>
						</view>
						<!-- ppt -->
						<view class='flex flex-wrap align-center justify-between prepare_fd3_0_c0'
							v-if=" item.file_type==4" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='prepare_fd3_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"1612.png"'>
								</image>
								<text class='prepare_fd3_0_c0_c0_c1'>{{item.name}}</text>
							</view>
							<button class='prepare_fd3_0_c0_c1'
								@tap="seePdf(item.file_path[0],item.aid)">{{$t('查看')}}</button>
						</view>
						<!-- 文档 -->
						<view class='flex flex-wrap align-center justify-between prepare_fd3_0_c0'
							v-if=" item.file_type==7" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='prepare_fd3_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"1613.png"'>
								</image>
								<text class='prepare_fd3_0_c0_c0_c1'>{{item.name}}</text>
							</view>
							<button class='prepare_fd3_0_c0_c1'
								@tap="seePdf(item.file_path[0],item.aid)">{{$t('查看')}}</button>
						</view>
						<!-- 图片 -->
						<view class='flex flex-wrap align-center justify-between prepare_fd3_0_c0'
							v-if=" item.file_type==1" :key='key0'>
							<view class='flex flex-wrap align-center'>
								<image class='prepare_fd3_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"1614.png"'>
								</image>
								<text class='prepare_fd3_0_c0_c0_c1'>{{item.name}}</text>
							</view>
							<button class='prepare_fd3_0_c0_c1'
								@tap="seePdf(item.file_path[0],item.aid)">{{$t('查看')}}</button>
						</view>

					</view>



				</view>
			</view>

			<!---flex布局flex布局结束-->
			<view class="flex benben-position-layout flex flex-wrap align-center prepare_flex_4"
				:style="{height:(110+bottomSafeAreaRpx)+'rpx',paddingBottom:bottomSafeAreaRpx+'rpx', }">
				<button class='prepare_fd4_0' @click="navs">{{$t('预习测试')}}</button>
			</view>
			<view :style="{height: (110+bottomSafeAreaRpx)+'rpx'}"></view>


		</view>
	</page-body>
</template>
<script>
	import {
		mdToHtml
	} from '@/common/utils/mdParser.js'
	export default {
		components: {},


		data() {
			return {
				"fd2_0_c1_c0_c1": 2,
				"fd2_0_c1_c1_c1": 2,
				"fd2_1_c1_c0_c1": 2,
				"fd2_1_c1_c1_c1": 2,
				"analyse": "",
				"tabsInfofd1_0": {
					lineleft: '',
					lineWidth: '',
					moveX: 0,
					scrollX: 0,
					PageScrollX: 0,
					isInit: false
				},
				list: [],
				"tabs": [{
					"name": "预习知识点",
					"value": "1",
					"image": ""
				}, {
					"name": "预习资料",
					"value": "2",
					"image": ""
				}],
				"tabsVal": "1",
				"tabsLab": "",
				"classname": "",
				"classhourName": "",
				"datum": "",
				"aid": "",
				lessonplanning_id: ""
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			let {
				lessonplanning_id,
				aid,
				classhourName,
				classname
			} = options
			if (lessonplanning_id != undefined) this.lessonplanning_id = lessonplanning_id
			if (classhourName != undefined) this.classhourName = classhourName
			if (classname != undefined) this.classname = classname
			if (aid != undefined) this.aid = aid
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.get6690ebae3b794()
			this.getrr68f99801dcf8Func()
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			aianalyse(id, name) {
				this.list.forEach(item => {
					item.show = false
					if (item.aid == id) {
						item.show = true
					}
				})
				this.get662c96aab794d(name)
				this.$forceUpdate()
			},
			seePdf(file, aid) {
				let _this = this;
				let id = aid;
				let url = file;
				// #ifdef APP-PLUS

				let files = uni.getStorageSync('files') ? JSON.parse(uni.getStorageSync('files')) : {}
				console.log(files)
				if (files[id]) {
					plus.runtime.openFile(files[id], {}, (res) => {
						console.log("res=>", res);
					})
				} else {
					downloadFile()
				}

				function downloadFile() {
					uni.showLoading({
						title: '加载中'
					})
					const dtask = plus.downloader.createDownload(url, {}, function(d, status) {
						if (status == 200) {
							console.log('保存成功')
							_this.aid = aid
							uni.hideLoading();
							files[id] = d.filename
							uni.setStorageSync('files', JSON.stringify(files))
							plus.runtime.openFile(d.filename)
						} else {
							plus.downloader.clear()
							uni.hideLoading();
							uni.showToast({
								title: '文档加载失败，请稍后再试',
								icon: 'none',
							})
						}
					})
					dtask.start()
				}
				// #endif

				// #ifdef H5
				window.open(url)
				// #endif
			},
			//备课管理-获取课件列表
			async getrr68f99801dcf8Func() {
				//请求方法
				//数据验证
				let datadatum = await this.$api.get(global.apiUrls.post668f99801dcf8, {
					lessonplanning_id: this.lessonplanning_id
				});

				if (datadatum.data.code != 1) {
					this.$message.info(datadatum.data.msg);
					return
				}
				let infodatum = datadatum.data;
				this.datum = infodatum.data

			},
			async get662c96aab794d(name) {
				this.analyse = ""
				let data662c96aab794d = await this.$api.post(global.apiUrls.post662c96aab794d, {
					content: `针对一名学生，在进行课前预习时，请针对课程【${this.classname}】内【${this.classhourName}】下的【${name}】进行分析，指导学生进行预习`
				})
				if (data662c96aab794d.data.code != 1) {
					this.$message.info(data662c96aab794d.data.msg);
					return
				}
				let info662c96aab794d = data662c96aab794d.data.data
				this.analyse = mdToHtml(info662c96aab794d.choices[0].message.content)
				this.$forceUpdate()
			},
			async get6690ebae3b794() {
				let data6690ebae3b794 = await this.$api.post(global.apiUrls.post6690ebae3b794, {
					lessonplanning_id: this.lessonplanning_id
				})
				if (data6690ebae3b794.data.code != 1) {
					this.$message.info(data6690ebae3b794.data.msg);
					return
				}
				let info6690ebae3b794 = data6690ebae3b794.data.data
				console.log("data6690ebae3b794=>", info6690ebae3b794)
				this.list = info6690ebae3b794
				this.list.forEach(item => {
					item.show = false
				})
			},
			async navs() {
				// 查看预习测试有没有发布
				let res = await this.$api.post(global.apiUrls.post669e09ab2af21, {
					teaching_id: this.aid,
					type: 1
				})

				if (res.data.code != 1) {
					this.$message.info(res.data.msg);
					return
				}

				uni.navigateTo({
					url: "/pages/course/answer/answer?teaching_id=" + this.aid
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.tab-outer {
		z-index: 99;
	}

	.page {
		width: 100vw;
		height: calc(100vh - var(--window-bottom));
		background: #F8F8F8;
		background-size: 100% auto;
		overflow: hidden;
		position: relative;
	}

	.prepare_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 99;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.prepare_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 700;
		color: #333333;
		line-height: 50rpx;
	}

	.prepare_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
	}

	.prepare_fd0_0_c0 {
		width: 120rpx;
	}

	.prepare_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.prepare_linefd1_0 {
		background: #145efd;
		width: 50rpx;
		height: 8rpx;
		top: 80rpx;
		background-size: 100% auto !important;
	}

	.checkTitlefd1_0 {
		font-weight: 700 !important;
		font-size: 28rpx !important;
		color: #333 !important;
	}

	.checkTitlefd1_0_all {
		padding-bottom: 10rpx;
	}

	::v-deep .prepare_benbenTabsfd1_0 {
		width: 750rpx;
		height: 90rpx;
		white-space: nowrap;
		text-align: center;
	}

	.prepare_flex_2 {
		padding: 15rpx 24rpx 32rpx 24rpx;
		height: calc(100vh - 280rpx);
		overflow: hidden;
		overflow-y: auto;
	}

	::v-deep .prepare_fd2_0_c2_c1 {
		width: 100%;
	}

	.prepare_fd2_0_c2_c0_c0 {
		color: rgba(20, 94, 253, 1);
		line-height: 40rpx;
		font-weight: 500;
		font-size: 28rpx;
	}

	.prepare_fd2_0_c2 {
		background: #f3f6f8;
		background-size: 100% auto;
		border-radius: 16rpx;
		padding: 24rpx;
	}

	.prepare_star1fd2_0_c1_c1_c1 {
		width: 24rpx;
		height: 24rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
	}

	.prepare_star1fd2_0_c1_c0_c1 {
		height: 24rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
		width: 24rpx;
	}

	.prepare_star1fd2_0_c1_c0_c1 {
		width: 24rpx;
		height: 24rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
	}

	.prepare_fd2_0_c1_c0_c0 {
		margin: 0rpx 16rpx 0rpx 0rpx;
		color: rgba(153, 153, 153, 1);
		font-size: 24rpx;
	}

	.prepare_fd2_0_c1 {
		margin: 0rpx 0rpx 24rpx 0rpx;
	}

	.prepare_fd2_0_c0_c2 {
		width: 28rpx;
		height: 28rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.prepare_fd2_0_c0_c1 {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 48rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.prepare_fd2_0_c0_c0 {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 48rpx;
	}

	.prepare_fd2_0_c0 {
		margin: 0rpx 0rpx 18rpx 0rpx;
	}

	.prepare_fd2_0 {
		background: var(--benbenbgColor1);
		margin: 0rpx 0rpx 24rpx 0rpx;
		border-radius: 16rpx;
		background-size: 100% auto;
		padding: 32rpx 24rpx 32rpx 24rpx;
	}

	.prepare_fd3_0_c0_c1 {
		background: rgba(20, 94, 253, .1);
		border-radius: 33rpx 33rpx 33rpx 33rpx;
		width: 96rpx;
		line-height: 48rpx;
		font-size: 24rpx;
		color: rgba(20, 94, 253, 1);
	}

	.prepare_fd3_0_c0_c0_c1 {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
		width: 450rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		// background-color: red;
	}

	.prepare_fd3_0_c0_c0_c0 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 016rpx 0rpx 0rpx;
	}

	.prepare_fd3_0_c0 {
		background: var(--benbenbgColor1);
		padding: 32rpx 24rpx 024rpx 24rpx;
		// margin: 0rpx 24rpx 24rpx 24rpx;
		border-radius: 32rpx;
		background-size: 100% auto;
		height: 104rpx;
	}

	.prepare_fd3_0 {
		padding: 0rpx 0rpx 0rpx 0rpx;
	}

	.prepare_flex_4 {
		width: 750rpx;
		height: 110rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		left: 0rpx;
		border-radius: 0rpx;
	}

	.prepare_fd4_0 {
		background: #4781f5;
		width: 100%;
		line-height: 110rpx;
		font-size: 32rpx;
		color: #fff;
		border-radius: 0rpx;
	}
</style>